﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace QUAN_LY_MUON_TRA_SACH
{
    public partial class frmhuydocgia : Form
    {
        public frmhuydocgia()
        {
            InitializeComponent();
        }

        private void frmhuydocgia_Load(object sender, EventArgs e)
        {
            cbomathe.Focus();
            try
            {
                DataTable bang = new DataTable();
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select mathe,hten_dg,ttrangthe from the_doc_gia", Connection.sqlConnection);
                sqlDataAdapter.Fill(bang);
                cbomathe.DataSource = bang;
                cbomathe.ValueMember = "mathe";
                sqlDataAdapter.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi: "+ex.Message);
            }
        }

        private void btnthoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnxoa_Click(object sender, EventArgs e)
        {
            if (cbomathe.Text != "")
            {
                try
                {
                    SqlCommand lenh = new SqlCommand("delete from the_doc_gia where mathe='" + cbomathe.Text + "'", Connection.sqlConnection);
                    int n = lenh.ExecuteNonQuery();
                    MessageBox.Show("Đọc giả đã được xóa!", "Cập nhật thành công", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    lenh.Dispose();
                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Lỗi: " + ex.Message);
                }
            }
            else
                MessageBox.Show("Bạn chưa chọn đọc giả để xóa!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
}
